from django.shortcuts import render

# Create your views here.
from django.views import View

from apps.contents.models import ContentCategory
from apps.contents.utils import get_categories


class IndexView(View):
    def get(self, request):
        """
        1、分类信息
        2、楼层信息
        """
        # 分类信息在其他页面也显示，所以就抽取为一个方法
        categories = get_categories()
        # 广告数据
        contents = {}
        content_categories = ContentCategory.objects.all()
        for cat in content_categories:
            contents[cat.key] = cat.content_set.filter(status=True).order_by('sequence')

        # 渲染模板的上下文
        context = {
            'categories': categories,
            'contents': contents,
        }
        return render(request, 'index.html', context=context)

# # 1、导入
# from fdfs_client.client import Fdfs_client
#
# # 2、创建客户端实例，加载指定配置文件
# client = Fdfs_client('utils/fdfs/client.conf')
#
# # 3、上传图片

# # filename写绝对路径
# client.upload_by_filename('/home/sun/Desktop/test.jpg')
